package com.thlws.redis.datatype;

import redis.clients.jedis.Jedis;

import java.util.List;

/**
 * @author HanleyTang
 * @date 2018-12-15
 */
public class JedisList {

    public static void main(String[] args) {


        try(Jedis jedis = new Jedis("localhost",6379);){

            //List左边放入值
            jedis.lpush("list1", "a", "b", "c");//c b a

            //List右边放入值
            jedis.rpush("list1","d","e","f"); // c b a d e f

            //从左|右 边取出一个值
            jedis.lpop("list1");
            jedis.rpop("list1");

            long len = jedis.llen("list1");
            System.out.println(len);

            //取list指定位置的原始
            String val = jedis.lindex("list1", 2);

            System.out.println(val);

            //取得部分或全部元素
            List<String> stringList = jedis.lrange("list1", 1, 3);//stop=-1,表示全部
            for (String s:stringList
                 ) {
                System.out.println(s);
            }

        }

    }
}
